<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="FOLDERS_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="BROWSER_DOCUMENTS_CURRENT_PATH_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="BROWSER_DOCUMENTS_COLLECTION_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="BROWSE_DOCUMENTS_GRID" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="CURRENT_PATH_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" scope="page" var="HTML_INPUT_TAG_ID_KEY" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />
<c:set var="inputId" value="${sessionScope[pageScope.HTML_INPUT_TAG_ID_KEY]}" />
<c:set var="currentPath" value="${requestScope[pageScope.CURRENT_PATH_KEY]}" />
<c:set var="path" value="/" />
<c:if test="${currentPath.numberOfFolders> 1}">
	<atleap:iterator items="${currentPath.folders}" var="folder" end="${currentPath.numberOfFolders - 2}">
		<atleap:rewriteUrl action="/core/browser/browseDocuments"  var="folderLink">
			<atleap:param name="currentFolder" value="${folder.fullPath}" />
		</atleap:rewriteUrl>
		<c:set var="folderLink" value="<a href=\"${folderLink}\">${folder.name}</a>" />
	    <c:set var="path" value="${path}${folderLink}/" />
    </atleap:iterator>
</c:if>
<c:if test="${currentPath.numberOfFolders> 0}">
	<c:set var="path" value="${path}${currentPath.lastFolder.name}/" />
</c:if>

<script type="text/javascript">
    brCurFolder = "${path}";
    brCurResourceType = "document";
</script>

<atleap:grid name="${pageScope.BROWSE_DOCUMENTS_GRID}" pageSize="${pageSize}">
    <table border="0" cellpadding="0" cellspacing="0" class="grid">
        <thead>
            <tr>
                <th nowrap="nowrap" colspan="8">
                    <atleap:message key="core.commons.currentPath" arg0="${path}" />
                </th>
            </tr>
            <tr>
                <th nowrap="nowrap">
                    <atleap:column fieldName="r.uri" fieldKey="core.contentResource.form.uri">
                        <atleap:sort rowIterators="documentIterator">
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
						</atleap:sort>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:column fieldName="r.mimeType" fieldKey="core.contentResource.form.mimeType">
                        <atleap:sort property="mimeType" rowIterators="documentIterator">
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                        </atleap:sort>
                        <atleap:setFilter beanId="lookupManager" method="listContentResourceMimeTypes">
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                        </atleap:setFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:message key="core.contentResource.form.description" />
                </th>
                <th nowrap="nowrap">
                    <atleap:column fieldName="r.contentLocale.identifier" fieldKey="core.contentResource.form.language">
                        <atleap:sort property="contentLocale.identifier" rowIterators="documentIterator">
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                        </atleap:sort>
                        <atleap:stringFilter>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                        </atleap:stringFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
					<atleap:message key="core.contentResource.form.size" />
                </th>
                <th>
                    <atleap:column fieldName="role.name" fieldKey="core.contentResource.form.role">
                        <atleap:message key="core.contentResource.form.roles" />
                        <atleap:setFilter beanId="lookupManager" method="listRolesAssignedToDocuments" value="name" label="title" rowIterators="crIterator">
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                         </atleap:setFilter>
                    </atleap:column>
                </th>
                <th colspan="2"><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  /></th>
            </tr>
        </thead>
        <tbody>
            <atleap:contextMenu var="folderMenuId">
                <atleap:rowsIterator tagId="folderIterator" var="folder" collection="${requestScope[pageScope.FOLDERS_COLLECTION_KEY]}" oddClass="oddRow" evenClass="evenRow">
                    <atleap:itemSet>
                        <atleap:rewriteUrl action="core/browser/browseDocuments" var="defaultUrl">
                            <atleap:param name="currentFolder" value="${folder.fullPath}" />
                        </atleap:rewriteUrl>
                        <tr class="${rowClass}" oncontextmenu="return showContextMenu(${folderMenuId}, event, ${indexId});" onclick="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);">
                            <td colspan="8">
                                <atleap:link action="core/browser/browseDocuments">
                                    <atleap:param name="currentFolder" value="${folder.fullPath}" />
                                    /<c:out value="${folder.name}" escapeXml="true" />
                                </atleap:link>
                            </td>
                            <atleap:item includeInPage="false">
                                <atleap:itemEnabled>
                                    <atleap:message key="core.commons.folders.openFolder" var="openFolderMsg" />
                                    <atleap:itemLink action="core/browser/browseDocuments" title="${openFolderMsg}">
                                        <atleap:param name="currentFolder" value="${folder.fullPath}" />
                                        <atleap:itemLabel>
                                            ${openFolderMsg}
                                        </atleap:itemLabel>
                                    </atleap:itemLink>
                                </atleap:itemEnabled>
                            </atleap:item>
                        </tr>
                    </atleap:itemSet>
                </atleap:rowsIterator>
            </atleap:contextMenu>
            <atleap:rowsIterator tagId="documentIterator" collection="${requestScope[pageScope.BROWSER_DOCUMENTS_COLLECTION_KEY]}" var="document" firstRowEven="false" oddClass="oddRow" evenClass="evenRow">
                <tr class="${rowClass}">
					<c:set var="uri" value="rw/resource${currentPath}${document.uri}" />
					<td class="defaultCursorCell"><c:out value="${document.uri}" escapeXml="true" /></td>
					<td class="defaultCursorCell"><c:out value="${document.mimeType}" escapeXml="true" /></td>
					<td class="defaultCursorCell">
                        <atleap:fieldValue valueMap="${document.description}" filter="true" />
                    </td>
					<td class="defaultCursorCell"><c:out value="${document.contentLocale.identifier}" escapeXml="true" /></td>
					<td class="defaultCursorCell"><c:out value="${document.size}" escapeXml="true" /></td>
					<td class="defaultCursorCell"><c:out value="${document.rolesAsString}" escapeXml="true" /></td>
					<td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
						<c:choose>
							<c:when test="${empty inputId}">
								<c:set var="onclickFunction" value="sendUrl(&#039;${uri}?view=true&#039;); return false;" />
							</c:when>
							<c:otherwise>
								<c:set var="onclickFunction" value="sendUrl(&#039;${uri}?view=true&#039;, &#039;${inputId}&#039;); return false;" />
							</c:otherwise>
						</c:choose>
						<a href="javascript:void(0)" onclick="${onclickFunction}" title="<atleap:message key="core.document.buttons.linkView" />">
							<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/view.gif" />" border="0" title="<atleap:message key="core.document.buttons.linkView" />" alt="<atleap:message key="core.file.buttons.linkView" />"  />
						</a>
					</td>
					<td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
						<c:choose>
							<c:when test="${empty inputId}">
								<c:set var="onclickFunction" value="sendUrl(&#039;${uri}?download=true&#039;); return false;" />
							</c:when>
							<c:otherwise>
								<c:set var="onclickFunction" value="sendUrl(&#039;${uri}?download=true&#039;, &#039;${inputId}&#039;); return false;" />
							</c:otherwise>
						</c:choose>
						<a href="javascript:void(0)" onclick="${onclickFunction}" title="<atleap:message key="core.document.buttons.linkDownload" />">
							<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/download.gif" />" border="0" title="<atleap:message key="core.document.buttons.linkDownload" />" alt="<atleap:message key="core.file.buttons.linkDownload" />" />
						</a>
					</td>
                </tr>
            </atleap:rowsIterator>
            <atleap:noRows>
                <tr>
                    <td class="tfoot" colspan="8" align="center">
                        <em><atleap:message key="core.browser.documentTab.noDocuments"/></em>
                    </td>
                </tr>
            </atleap:noRows>
        </tbody>
        <tfoot>
            <tr>
                <atleap:pager pageCount="10">
                    <td colspan="8" align="center">
                       <atleap:message key="core.grid.pager.title" />&nbsp;
                       <atleap:firstPage><img src="<atleap:rewriteUrl href="/imagess/core/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                       <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                       <atleap:pagesIterator>
                           <atleap:page>${pageNumber}&nbsp;</atleap:page>
                           <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                       </atleap:pagesIterator>
                       <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                       <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                    </td>
                </atleap:pager>
            </tr>
        </tfoot>
    </table>
</atleap:grid>


